package com.example.woke;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.Display;
import android.view.GestureDetector;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ViewFlipper;

import com.http.HttpMethods;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.JsonHttpResponseHandler;
import com.loopj.android.http.PersistentCookieStore;
import com.loopj.android.http.RequestParams;
import com.woke.data.Data_mylist;
import com.woke.diyview.CalendarGridView;
import com.woke.diyview.CalendarGridViewAdapter;
import com.woke.diyview.NumberHelper;
import com.woke.method.Intentnet;
import com.woke.method.MyApp;
import com.zhongcai.online.R;

import org.apache.http.Header;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;

import static com.zhongcai.online.R.string.user_balance_money_f4;

public class Mylist_checkActivity extends Activity implements OnTouchListener, OnItemClickListener {

	//�ж�������
	private static final int SWIPE_MIN_DISTANCE = 120;
	private static final int SWIPE_MAX_OFF_PATH = 250;
	private static final int SWIPE_THRESHOLD_VELOCITY = 200;

	//����
	private Animation slideLeftIn;
	private Animation slideLeftOut;
	private Animation slideRightIn;
	private Animation slideRightOut;
	private ViewFlipper viewFlipper;
	GestureDetector mGesture = null;

	// �����
	private Context mContext = Mylist_checkActivity.this;
	private GridView title_gView;
	private GridView gView1;// ��һ����
	private GridView gView2;// ��ǰ��
	private GridView gView3;// ��һ����
	// private GridView gView1;
	boolean bIsSelection = false;// �Ƿ���ѡ���¼�����
	private Calendar calStartDate = Calendar.getInstance ();// ��ǰ��ʾ������
	private Calendar calSelected = Calendar.getInstance (); // ѡ�������
	private Calendar calToday = Calendar.getInstance (); // ����
	private CalendarGridViewAdapter gAdapter;
	private CalendarGridViewAdapter gAdapter1;
	private CalendarGridViewAdapter gAdapter3;
	// ������ť
	private Button btnToday = null;
	private RelativeLayout mainLayout;

	//
	private int iMonthViewCurrentMonth = 0; // ��ǰ��ͼ��
	private int iMonthViewCurrentYear = 0; // ��ǰ��ͼ��
	private int iFirstDayOfWeek = Calendar.MONDAY;

	private static final int mainLayoutID = 88; // ����������ID
	private static final int titleLayoutID = 77; // title����ID
	private static final int caltitleLayoutID = 66; // title����ID
	private static final int calLayoutID = 55; // �����ID
	/**
	 * �ײ��˵�����
	 **/
	String[] menu_toolbar_name_array;

	private String sssss;
	private TextView mText;
	private ImageView mText1, mText3;
	private RelativeLayout mRelat;
	private View ksdlf;
	private EditText mTstart, mTend;
	public boolean whicj;//�ж���ʼʱ���

	private ArrayList<Data_mylist> datalist = new ArrayList<Data_mylist> ();
	private MyApp application;
	private ListView mListView;
	private View viewlist;
	private Myadapter adapter;
	private Intentnet net;
	SimpleDateFormat sdf = new SimpleDateFormat ("yyyy-MM-dd");
	private String user_balance_money_f;
	String defalt_df = "0.00";
	DecimalFormat ddf = new DecimalFormat (defalt_df);//保留两位小数

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate (savedInstanceState);
		setContentView (R.layout.activity_mylist_check);
		user_balance_money_f = getResources ().getString (user_balance_money_f4);
		application = (MyApp) getApplication ();
		ksdlf = generateContentView ();
		UpdateStartDateForMonth ();
		net = new Intentnet ();
		intview ();

	}

	public void texttext(String str1) {
		String trim = mText.getText ().toString ().trim ();
		if (mTstart.hasFocus () == true) {
			mTstart.setText (trim + "月" + str1 + "日");
		} else {
			mTend.setText (trim + "月" + str1 + "日");

		}
//		if(whicj == false){
//		}else{
//		}
	}

	// ��ݸı�����ڸ�������
	// �������ؼ���
	private void UpdateStartDateForMonth() {
		calStartDate.set (Calendar.DATE, 1); // ���óɵ��µ�һ��
		iMonthViewCurrentMonth = calStartDate.get (Calendar.MONTH);// �õ���ǰ������ʾ����
		iMonthViewCurrentYear = calStartDate.get (Calendar.YEAR);// �õ���ǰ������ʾ����

		sssss = calStartDate.get (Calendar.YEAR)
				+ "年"
				+ NumberHelper.LeftPad_Tow_Zero (calStartDate
				.get (Calendar.MONTH) + 1);
		mText.setText (sssss);

		// ����һ��2 ��������1 ���ʣ������
		int iDay = 0;
		int iFirstDayOfWeek = Calendar.MONDAY;
		int iStartDay = iFirstDayOfWeek;
		if (iStartDay == Calendar.MONDAY) {
			iDay = calStartDate.get (Calendar.DAY_OF_WEEK) - Calendar.MONDAY;
			if (iDay < 0)
				iDay = 6;
		}
		if (iStartDay == Calendar.SUNDAY) {
			iDay = calStartDate.get (Calendar.DAY_OF_WEEK) - Calendar.SUNDAY;
			if (iDay < 0)
				iDay = 6;
		}
		calStartDate.add (Calendar.DAY_OF_WEEK, - iDay);

	}

	private void getlistlistdata(String time, String time1) {
		if (application.getDatas_load () == null) return;
		AsyncHttpClient ahc = new AsyncHttpClient ();
		PersistentCookieStore myCookieStore = new PersistentCookieStore (
				Mylist_checkActivity.this);
		ahc.setCookieStore (myCookieStore);
		RequestParams params = new RequestParams ();
		params.put ("g", "api");
		params.put ("m", "user");
		params.put ("a", "moneyLoglist");
		params.put ("userid", application.getDatas_load ().getId ());
		params.put ("starttime", time);
		params.put ("endtime", time1);
		ahc.get (HttpMethods.BASEURL, params, new JsonHttpResponseHandler () {
			@Override
			public void onSuccess(int statusCode, Header[] headers,
					JSONObject response) {
				super.onSuccess (statusCode, headers, response);
				if (datalist.size () > 0) {
					datalist.clear ();
				}
				try {
					String flag = response.getString ("flag");
					if (flag.equals ("success")) {
						JSONObject jsonObject = response.getJSONObject ("data");
						JSONArray jsonArray = jsonObject.getJSONArray ("data");
						for (int i = 0; i < jsonArray.length (); i++) {
							JSONObject object = jsonArray.getJSONObject (i);
							long create_time = object.getLong ("create_time");
							String money = object.getString ("money");
							String id = object.getString ("id");
							String type = object.getString ("type");
							String status = object.getString ("status");
							String note = object.getString ("note");
							double actual_money = object.getDouble ("actual_money");
							double curr_money = object.getDouble ("curr_money");
							String fee = "";
							if (object.has ("fee")) {
								fee = object.getString ("fee");
							}

							Data_mylist list = new Data_mylist (create_time, money, id, type, status, note, actual_money, curr_money, fee);
							datalist.add (list);
						}
					} else if (flag.equals ("unknow")) {
						String info = response.getString ("info");
						Toast.makeText (Mylist_checkActivity.this, info, Toast.LENGTH_SHORT)
								.show ();
					}
				} catch (JSONException e) {
					e.printStackTrace ();
				}

				if (datalist.size () > 0) {
					adapter.notifyDataSetChanged ();
				}

			}

			@Override
			public void onFailure(int statusCode, Header[] headers,
					String responseString, Throwable throwable) {
				super.onFailure (statusCode, headers, responseString, throwable);
				Toast.makeText (Mylist_checkActivity.this, "数据失败！",
						Toast.LENGTH_SHORT).show ();
//					Log.e("������ǰ�dd", "ʧ��" + responseString);
			}

			@Override
			public void onStart() {
				// TODO Auto-generated method stub
				super.onStart ();

//					mBar.setVisibility(View.VISIBLE);

			}

			@Override
			public void onFinish() {
				super.onFinish ();
//					mBar.setVisibility(View.GONE);
//					Log.e("������ǰ�", "���");
			}
		});
	}

	class Myadapter extends BaseAdapter {

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return datalist.size ();
		}

		@Override
		public Object getItem(int i) {
			// TODO Auto-generated method stub
			return i;
		}

		@Override
		public long getItemId(int i) {
			// TODO Auto-generated method stub
			return i;
		}

		class Holder {
			TextView mTname;
			TextView mTmoney;
			TextView mTtime;
			TextView mTbalanceMoney;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			Holder holder = null;
			if (convertView == null) {
				holder = new Holder ();
				convertView = getLayoutInflater ().inflate (R.layout.item_adter_mylist, null);
				holder.mTname = (TextView) convertView.findViewById (R.id.item_mylist_name);
				holder.mTmoney = (TextView) convertView.findViewById (R.id.item_mylist_money);
				holder.mTtime = (TextView) convertView.findViewById (R.id.item_mylist_time);
				holder.mTbalanceMoney = (TextView) convertView.findViewById (R.id.item_balance_money);
				convertView.setTag (holder);
			} else {
				holder = (Holder) convertView.getTag ();
			}

			Data_mylist list = datalist.get (position);
			String status = list.status;
			String type = list.type;
			if (type.equals ("1")) {
				holder.mTname.setText ("会员充值");
			} else if (type.equals ("2")) {
				holder.mTname.setText ("会员提现");
			} else if (type.equals ("12")) {
				holder.mTname.setText ("会员升级");
			} else if (type.equals ("11")) {
				holder.mTname.setText ("管理员增金");
			} else if (type.equals ("3")) {
				holder.mTname.setText ("中财借贷");
			} else if (type.equals ("4")) {
				holder.mTname.setText ("中财理财");
			} else if (type.equals ("5")) {
				holder.mTname.setText ("中财支付");
			} else if (type.equals ("6")) {
				holder.mTname.setText ("财信通");
			} else if (type.equals ("7")) {
				holder.mTname.setText ("好友转账");
			} else if (type.equals ("71")) {
				holder.mTname.setText ("管理员转账");
			} else if (type.equals ("8")) {
				holder.mTname.setText ("中财众筹");
			} else if (type.equals ("9")) {
				holder.mTname.setText ("收益");
			} else if (type.equals ("91")) {
				holder.mTname.setText ("理财收益");
			} else if (type.equals ("92")) {
				holder.mTname.setText ("下线升级");
			} else if (type.equals ("93")) {
				holder.mTname.setText ("邀请下级");
			} else if (type.equals ("41")) {
				holder.mTname.setText ("活期理财");
			} else if (type.equals ("42")) {
				holder.mTname.setText ("定期理财");
			} else if (type.equals ("94")) {
				holder.mTname.setText ("下级分润");
			}
//			String strTime = Intentnet.getStrTime (list.create_time);
			holder.mTtime.setText (sdf.format (new Date (list.create_time * 1000L)));
			if (status.equals ("1")) {
				holder.mTmoney.setText ("-" + list.money);
			} else {
				holder.mTmoney.setText ("+" + list.money);
			}

			ddf.setRoundingMode (RoundingMode.FLOOR);
			String balanceMoney = ddf.format (list.curr_money);
			if (defalt_df.equals (balanceMoney)) {
				//历史数据有的返回0.00
				holder.mTbalanceMoney.setText ("----");
			} else {
				holder.mTbalanceMoney.setText (String.format (user_balance_money_f, balanceMoney));
			}
			return convertView;
		}
	}

	private void intview() {

		mRelat = (RelativeLayout) findViewById (R.id.avmylistcheck_relativew);
		mRelat.addView (ksdlf);
		viewlist = findViewById (R.id.avmylistcheck_rellistview);
		mTstart = (EditText) findViewById (R.id.ardialog_text_start);
		mTend = (EditText) findViewById (R.id.ardialog_text_end);
		mListView = (ListView) findViewById (R.id.avmylistcheck_listview);
		findViewById (R.id.avzcailistcheck_text_restart).setOnClickListener (new OnClickListener () {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				viewlist.setVisibility (View.GONE);
			}
		});
		findViewById (R.id.avmylistcheck_text_ok).setOnClickListener (new OnClickListener () {

			@Override
			public void onClick(View v) {
				String trim0 = "" + mTstart.getText ().toString ().trim ();
				String trim1 = "" + mTend.getText ().toString ().trim ();
				String time = Intentnet.getTime (trim0);
				String time1 = Intentnet.getTime (trim1);
				if (trim0.equals ("") && trim1.equals ("")) {
				} else {
					viewlist.setVisibility (View.VISIBLE);
					getlistlistdata (time, time1);

				}
			}
		});
//		boolean hasFocus = mTstart.hasFocus();
//		mTstart.setOnClickListener(new OnClickListener() {
//			
//			@Override
//			public void onClick(View v) {
//				whicj = false;
//				mRelat.setVisibility(View.VISIBLE);
//			}
//		});
//		mTend.setOnClickListener(new OnClickListener() {
//			
//			@Override
//			public void onClick(View v) {
//				whicj = true;
//				mRelat.setVisibility(View.VISIBLE);
//			}
//		});
		findViewById (R.id.avzcailistcheck_image_back).setOnClickListener (new OnClickListener () {

			@Override
			public void onClick(View v) {
				finish ();
			}
		});
		adapter = new Myadapter ();
		mListView.setAdapter (adapter);
		mListView.setOnItemClickListener (this);
	}

	// ���������ͼ
	private View generateContentView() {
		// ����һ����ֱ�����Բ��֣��������ݣ�
		viewFlipper = new ViewFlipper (this);
		viewFlipper.setId (calLayoutID);

		mainLayout = new RelativeLayout (this); // ����һ����ֱ�����Բ��֣��������ݣ�
		RelativeLayout.LayoutParams params_main = new RelativeLayout.LayoutParams (
				LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
		mainLayout.setLayoutParams (params_main);
		mainLayout.setId (mainLayoutID);
		mainLayout.setGravity (Gravity.CENTER_HORIZONTAL);

		View layTopControls = getLayoutInflater ().inflate (R.layout.layout_d, null);
		mText = (TextView) layTopControls.findViewById (R.id.textView2);
		mText1 = (ImageView) layTopControls.findViewById (R.id.textView1);
		mText3 = (ImageView) layTopControls.findViewById (R.id.textView3);
		mText1.setOnClickListener (new OnClickListener () {

			@Override
			public void onClick(View v) {
				viewFlipper.setInAnimation (slideRightIn);
				viewFlipper.setOutAnimation (slideRightOut);
				viewFlipper.showPrevious ();
				setPrevViewItem ();
			}
		});

		mText3.setOnClickListener (new OnClickListener () {

			@Override
			public void onClick(View v) {
				viewFlipper.setInAnimation (slideLeftIn);
				viewFlipper.setOutAnimation (slideLeftOut);
				viewFlipper.showNext ();
				setNextViewItem ();
			}
		});

//			generateTopButtons(layTopControls); // ��ɶ�����ť ����һ�£���һ�£���ǰ�£�
		RelativeLayout.LayoutParams params_title = new RelativeLayout.LayoutParams (
				LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
		params_title.topMargin = 5;
		// params_title.addRule(RelativeLayout.ALIGN_PARENT_TOP, 20);
		layTopControls.setId (titleLayoutID);
		mainLayout.addView (layTopControls, params_title);

		calStartDate = getCalendarStartDate ();

		setTitleGirdView ();
		RelativeLayout.LayoutParams params_cal_title = new RelativeLayout.LayoutParams (
				LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
		params_cal_title.addRule (RelativeLayout.BELOW, titleLayoutID);
		// params_cal_title.topMargin = 5;
		mainLayout.addView (title_gView, params_cal_title);

		CreateGirdView ();

		RelativeLayout.LayoutParams params_cal = new RelativeLayout.LayoutParams (
				LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
		params_cal.addRule (RelativeLayout.BELOW, caltitleLayoutID);

		mainLayout.addView (viewFlipper, params_cal);

		LinearLayout br = new LinearLayout (this);
		RelativeLayout.LayoutParams params_br = new RelativeLayout.LayoutParams (
				LayoutParams.FILL_PARENT, 1);
		params_br.addRule (RelativeLayout.BELOW, calLayoutID);
		br.setBackgroundColor (getResources ().getColor (R.color.usercenterbg));
		mainLayout.addView (br, params_br);

		return mainLayout;
	}

	private Calendar getCalendarStartDate() {
		calToday.setTimeInMillis (System.currentTimeMillis ());
		calToday.setFirstDayOfWeek (iFirstDayOfWeek);

		if (calSelected.getTimeInMillis () == 0) {
			calStartDate.setTimeInMillis (System.currentTimeMillis ());
			calStartDate.setFirstDayOfWeek (iFirstDayOfWeek);
		} else {
			calStartDate.setTimeInMillis (calSelected.getTimeInMillis ());
			calStartDate.setFirstDayOfWeek (iFirstDayOfWeek);
		}

		return calStartDate;
	}

	private void setTitleGirdView() {

		title_gView = setGirdView ();
		LinearLayout.LayoutParams params = new LinearLayout.LayoutParams (
				LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
		// params.topMargin = 5;
		title_gView.setLayoutParams (params);
		title_gView.setVerticalSpacing (0);// ��ֱ���
		title_gView.setHorizontalSpacing (0);// ˮƽ���
		TitleGridAdapter titleAdapter = new TitleGridAdapter (this);
		title_gView.setAdapter (titleAdapter);// ���ò˵�Adapter
		title_gView.setId (caltitleLayoutID);
	}

	private void CreateGirdView() {

		Calendar tempSelected1 = Calendar.getInstance (); // ��ʱ
		Calendar tempSelected2 = Calendar.getInstance (); // ��ʱ
		Calendar tempSelected3 = Calendar.getInstance (); // ��ʱ
		tempSelected1.setTime (calStartDate.getTime ());
		tempSelected2.setTime (calStartDate.getTime ());
		tempSelected3.setTime (calStartDate.getTime ());

		gView1 = new CalendarGridView (mContext);
		tempSelected1.add (Calendar.MONTH, - 1);
		gAdapter1 = new CalendarGridViewAdapter (this, tempSelected1);
		gView1.setAdapter (gAdapter1);// ���ò˵�Adapter
		gView1.setId (calLayoutID);

		gView2 = new CalendarGridView (mContext);
		gAdapter = new CalendarGridViewAdapter (this, tempSelected2);
		gView2.setAdapter (gAdapter);// ���ò˵�Adapter
		gView2.setId (calLayoutID);

		gView3 = new CalendarGridView (mContext);
		tempSelected3.add (Calendar.MONTH, 1);
		gAdapter3 = new CalendarGridViewAdapter (this, tempSelected3);
		gView3.setAdapter (gAdapter3);// ���ò˵�Adapter
		gView3.setId (calLayoutID);

		gView2.setOnTouchListener (this);
		gView1.setOnTouchListener (this);
		gView3.setOnTouchListener (this);

		if (viewFlipper.getChildCount () != 0) {
			viewFlipper.removeAllViews ();
		}

		viewFlipper.addView (gView2);
		viewFlipper.addView (gView3);
		viewFlipper.addView (gView1);

		String s = calStartDate.get (Calendar.YEAR)
				+ "-"
				+ NumberHelper.LeftPad_Tow_Zero (calStartDate
				.get (Calendar.MONTH) + 1);

		Log.e ("s", s);
//			btnToday.setText(s);
		mText.setText (s);
	}

	private GridView setGirdView() {
		LinearLayout.LayoutParams params = new LinearLayout.LayoutParams (
				LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
		GridView gridView = new GridView (this);
		gridView.setLayoutParams (params);
		gridView.setNumColumns (7);// ����ÿ������
		gridView.setGravity (Gravity.CENTER_VERTICAL);// λ�þ���
		gridView.setVerticalSpacing (1);// ��ֱ���
		gridView.setHorizontalSpacing (1);// ˮƽ���
		gridView.setBackgroundColor (getResources ().getColor (
				R.color.white));

		WindowManager windowManager = getWindowManager ();
		Display display = windowManager.getDefaultDisplay ();
		int i = display.getWidth () / 7;
		int j = display.getWidth () - (i * 7);
		int x = j / 2;
		gridView.setPadding (x, 0, 0, 0);// ����

		return gridView;
	}

	// ��һ����
	private void setPrevViewItem() {
		iMonthViewCurrentMonth--;// ��ǰѡ����--
		// ���ǰ��Ϊ����Ļ���ʾ��һ��
		if (iMonthViewCurrentMonth == - 1) {
			iMonthViewCurrentMonth = 11;
			iMonthViewCurrentYear--;
		}
		calStartDate.set (Calendar.DAY_OF_MONTH, 1); // ������Ϊ����1��
		calStartDate.set (Calendar.MONTH, iMonthViewCurrentMonth); // ������
		calStartDate.set (Calendar.YEAR, iMonthViewCurrentYear); // ������
		CreateGirdView ();
	}

	// ����
	private void setToDayViewItem() {

		calSelected.setTimeInMillis (calToday.getTimeInMillis ());
		calSelected.setFirstDayOfWeek (iFirstDayOfWeek);
		calStartDate.setTimeInMillis (calToday.getTimeInMillis ());
		calStartDate.setFirstDayOfWeek (iFirstDayOfWeek);

//			Toast.makeText(BaseCalendar.this, ""+calToday.getTimeInMillis()+calToday.getTimeInMillis(), Toast.LENGTH_LONG).show();

	}

	// ��һ����
	private void setNextViewItem() {
		iMonthViewCurrentMonth++;
		if (iMonthViewCurrentMonth == 12) {
			iMonthViewCurrentMonth = 0;
			iMonthViewCurrentYear++;
		}
		calStartDate.set (Calendar.DAY_OF_MONTH, 1);
		calStartDate.set (Calendar.MONTH, iMonthViewCurrentMonth);
		calStartDate.set (Calendar.YEAR, iMonthViewCurrentYear);
		CreateGirdView ();
	}

	public class TitleGridAdapter extends BaseAdapter {

		int[] titles = new int[]{R.string.Sun, R.string.Mon, R.string.Tue,
				R.string.Wed, R.string.Thu, R.string.Fri, R.string.Sat};

		private Activity activity;

		// construct
		public TitleGridAdapter(Activity a) {
			activity = a;
		}

		public int getCount() {
			return titles.length;
		}

		public Object getItem(int position) {
			return titles[position];
		}

		public long getItemId(int position) {
			return position;
		}

		public View getView(int position, View convertView, ViewGroup parent) {
			LinearLayout iv = new LinearLayout (activity);
			final TextView txtDay = new TextView (activity);
			txtDay.setFocusable (false);
			txtDay.setBackgroundColor (Color.TRANSPARENT);
			iv.setOrientation (1);

			txtDay.setGravity (Gravity.CENTER);
			LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams (
					LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);

			int i = (Integer) getItem (position);

			txtDay.setTextColor (Color.WHITE);
			Resources res = getResources ();

			if (i == R.string.Sat) {
				// ����
				txtDay.setBackgroundColor (res.getColor (R.color.title_text_6));
			} else if (i == R.string.Sun) {
				// ����
				txtDay.setBackgroundColor (res.getColor (R.color.title_text_7));
			} else {

			}

			txtDay.setText ((Integer) getItem (position));
			txtDay.setOnClickListener (new OnClickListener () {

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					Toast.makeText (Mylist_checkActivity.this, sssss + txtDay.getText ()
							.toString (), Toast.LENGTH_LONG).show ();
				}
			});

			iv.addView (txtDay, lp);

			return iv;
		}
	}

	@Override
	public boolean onTouch(View v, MotionEvent event) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
			long arg3) {
		Intent intent = new Intent (Mylist_checkActivity.this, Zcailist_infoActivity.class);
		intent.putExtra ("id", datalist.get (arg2).id);
		startActivity (intent);
	}

}
